﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;


namespace PRE
{
    public partial class FrmMain : RibbonForm
    {

        private const string STR_LOGIN = "Đăng &nhập";
        private const string STR_LOGOUT = "Đăng &xuất";

        public static UTL.Session _sss = new UTL.Session();
        public static string _User;

        public FrmMain()
        {
            InitializeComponent();
            InitSkinGallery();

        }
        void InitSkinGallery()
        {
            SkinHelper.InitSkinGallery(rgbiSkins, true);
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            btdangnhap_ItemClick(null, null);
        }

        private void EnableMenu()
        {
            switch (_sss.Role)
            {
                case UTL.Session.Roles.Admin:

                    btthanhvien.Enabled = true;

                    break;

                case UTL.Session.Roles.user:

                    btthanhvien.Enabled = false;
                    break;
                default:
                    break;
            }
        }


        private void btdangnhap_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (btdangnhap.Caption == STR_LOGOUT)
            {
                _sss.Login = false;
                btdangnhap.Caption = STR_LOGIN;

                btDongtacca_ItemClick(sender, e);
            }

            catalog.Frmdangnhap x = new catalog.Frmdangnhap();
            x.ShowDialog();

            if (_sss.Login)
            {
                //bsiUser.Caption = _sss.Name;
                bsiMA_NV.Caption = _sss.Name;
                btdangnhap.Caption = STR_LOGOUT;

                //rpDanhmuc.Visible = true;
                //rpThongke.Visible = true;
                //rpgNguoidung.Visible = true;
                //rpgDangky.Visible = true;
                //bbiDoimatkhau.Visibility = BarItemVisibility.Always;
            }
            else
            {
                //  rpDanhmuc.Visible = false;
                //  rpThongke.Visible = false;
                //rpgNguoidung.Visible = false;
                //rpgDangky.Visible = false;
                //rpgDiemthi.Visible = false;
                //bbiDoimatkhau.Visibility = BarItemVisibility.Never;
            }

            EnableMenu();

        }

        private void btDongtacca_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var frm in MdiChildren) frm.Close();
            picBackGround.Visible = true;
        }

        private void btThoat_ItemClick(object sender, ItemClickEventArgs e)
        {
            Application.Exit();
        }

        private void btnganh_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmNganh) return;
            var frm = new catalog.FrmNganh() { MdiParent = this };

            frm.Show();
            picBackGround.Visible = false;
        }

        private void btlinhvuc_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmLinhVuc) return;
            var frm = new catalog.FrmLinhVuc() { MdiParent = this };

            frm.Show();
            picBackGround.Visible = false;
        }

        private void btgpsx_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmGiayPhepSanXuat) return;
            var frm = new catalog.FrmGiayPhepSanXuat() { MdiParent = this };

            frm.Show();
            picBackGround.Visible = false;
        }

        private void btsanpham_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmSanPham) return;
            var frm = new catalog.FrmSanPham() { MdiParent = this };

            frm.Show();
            picBackGround.Visible = false;
        }

        private void btdoanhnghiep_ItemClick(object sender, ItemClickEventArgs e)
        {

            foreach (var x in MdiChildren) if (x is catalog.FrmDoanhNghiep) return;
            var frm = new catalog.FrmDoanhNghiep() { MdiParent = this };

            frm.Show();
            picBackGround.Visible = false;
        }

        private void btspdn_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmSanPhamDoanhNghiep) return;
            var frm = new catalog.FrmSanPhamDoanhNghiep() { MdiParent = this };

            frm.Show();
            picBackGround.Visible = false;
        }

        private void btsanxuat_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmSanXuat) return;
            var frm = new catalog.FrmSanXuat() { MdiParent = this };

            frm.Show();
            picBackGround.Visible = false;
        }

        private void btthanhvien_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is catalog.FrmTaiKhoan) return;
            var frm = new catalog.FrmTaiKhoan() { MdiParent = this };

            frm.Show();
            picBackGround.Visible = false;
        }

        private void btspsxcuadntheothoigian_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Thongke_Baocao.FrmSPSXcuaDNtrongkhoangti_hoigian) return;
            var frm = new Thongke_Baocao.FrmSPSXcuaDNtrongkhoangti_hoigian() { MdiParent = this };

            frm.Show();
            picBackGround.Visible = false;
        }

        private void bttkcacDNsxSPsaiLV_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var x in MdiChildren) if (x is Thongke_Baocao.FrmCacDNsaxxuatSPko_cungLV) return;
            var frm = new Thongke_Baocao.FrmCacDNsaxxuatSPko_cungLV() { MdiParent = this };

            frm.Show();
            picBackGround.Visible = false;
        }

    }
}
